﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business.Dal;
using System.Web.UI.MobileControls;
using Business.Entity;
using System.Collections.Generic;

namespace Sahibinden.UserAction
{
    public partial class MesajOku : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                FillData();
            }
        }

        private void FillData()
        {
            MesajProvider mp = new MesajProvider();
            List<Mesaj> lstMesajlar = mp.MesajlarAlanınSilmedikleriniGetir(Convert.ToInt32(Page.User.Identity.Name));

            GridView1.DataSource = lstMesajlar;
            GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Oku")
            {
                

                Response.Redirect("MesajDetails.aspx?MesajID=" + e.CommandArgument.ToString());
            }
        }

        protected void btnSil_Click(object sender, EventArgs e)
        {
           
        
            foreach (GridViewRow dr in GridView1.Rows)
            {
                CheckBox chk = (CheckBox)dr.Cells[0].FindControl("chkSil");
                if (chk.Checked)
                {
                    System.Web.UI.WebControls.Label lbl = (System.Web.UI.WebControls.Label)dr.Cells[3].FindControl("lblMesajID");
                    MesajProvider mp = new MesajProvider();
                    mp.Delete(Convert.ToInt32( lbl.Text));
                }
            }
            FillData();
        }

        protected void chkTumunuSil_CheckedChanged(object sender, EventArgs e)
        {
            bool chkFlag = false;
            if (((CheckBox)sender).Checked) chkFlag = true;
            foreach (GridViewRow dr in GridView1.Rows)
            {
                CheckBox chk = (CheckBox)dr.Cells[0].FindControl("chkSil");
                chk.Checked = chkFlag;
            }
        }
    }
}
